<template>

  <el-container class="home_container">
    <!-- 头部区域 -->
    <el-header>
      <div>
        <img
          src="../assets/heima.png"
          alt=""
        >
        <span>电商后台管理系统</span>
      </div>
      <el-button
        type="info"
        @click="logout"
      >退出</el-button>
    </el-header>
    <!-- 下部区域 -->
    <el-container>
      <!-- 左侧导航 -->

      <el-aside :width="isCollapse?'64px':'200px'">
        <div
          class="toggle"
          @click="isCollapse = !isCollapse"
        >| | |</div>
        <el-menu
          background-color="#343843"
          text-color="#fff"
          :collapse="isCollapse"
          :collapse-transition="false"
          unique-opened
          router
          :default-active="activeSet"
        >
          <el-submenu
            :index="obj.id + ''"
            v-for="obj in menuList"
            :key="obj.id"
          >
            <template slot="title">
              <i
                :class="iconsObj[obj.id]"
                style="margin-right:10px"
              ></i>
              <span>{{obj.authName}}</span>
            </template>
            <el-menu-item
              :index="'/'+item.path"
              v-for="item in obj.children"
              :key="item.id"
              @click="changeActive('/'+item.path)"
            >
              <template slot="title">
                <i
                  class="el-icon-football"
                  style="margin-right:10px"
                ></i>
                <span>{{item.authName}}</span>
              </template>
            </el-menu-item>
          </el-Submenu>
        </el-menu>
      </el-aside>
      <!-- 右侧主体区域 -->
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data () {
    return {
      menuList: [],
      iconsObj: {
        125: 'iconfont icon-user',
        103: 'iconfont icon-tijikongjian',
        101: 'iconfont icon-shangpin',
        102: 'iconfont icon-danju',
        145: 'iconfont icon-baobiao'
      },
      isCollapse: false,
      activeSet: ''
    }
  },
  methods: {
    logout () {
      window.sessionStorage.removeItem('token')
      this.$router.push('/login')
    },
    async getMenus () {
      const { data: res } = await this.$http.get('menus')
      if (res.meta.status !== 200) return this.$Message.error('获取数据失败')
      // console.log(res)
      this.menuList = res.data
      // console.log(this.menuList)
    },
    changeActive (activepath) {
      window.sessionStorage.setItem('activePath', activepath)
      this.activeSet = activepath
    }
  },
  computed: {},
  watch: {},
  filters: {},
  components: {},
  created () {
    this.getMenus()
    this.activeSet = window.sessionStorage.getItem('activePath')
  },
  mounted () { }
}
</script>

<style scoped lang='less'>
.home_container {
  height: 100%;
}
.el-header {
  background-color: #383c41;
  display: flex;
  justify-content: space-between;
  padding-left: 0;
  align-items: center;
  color: #fff;
  > div {
    display: flex;
    align-items: center;
    > span {
      margin-left: 15px;
    }
  }
}
.el-aside {
  background-color: #343843;
}
.el-menu {
  border-right: none;
}
.toggle {
  background-color: #232325;
  text-align: center;
  color: #fff;
  padding: 5px, 0;
}
.el-main{
  background-color: #eaedf1;
}
</style>
